import {queryAllSeller,queryAdminPowerList, updateAdminPower,queryPowerList} from "../services/adminPowerSettingApi";

export default {
    namespace: 'adminPowerSetting',
    state: {
        status: undefined,
        data:{
            list:[],
            pagination:{},
        },
        powerData:{
            list:[],
            pagination:{},
        },
        actionList:[],
        actionList2:[],
        sellerData:{
            list:[],
            pagination:{},
        },
        userId:'',
    },

    effects: {
        * queryAdminPowerList({payload}, {call, put}) {
            yield put({
                type: 'changeSubmitting',
                payload: true,
            });
            const response = yield call(queryAdminPowerList, payload);
            yield put({
                type: 'queryAdminPowerListHandle',
                payload: response,
            });
            yield put({
                type: 'changeSubmitting',
                payload: false,
            });
        },
        * updateAdminPower({payload, callback}, {call, put}) {
            yield put({
                type: 'changeSubmitting',
                payload: true,
            });
            const response = yield call(updateAdminPower, payload);
            yield put({
                type: 'changeSubmitting',
                payload: false,
            });
            if (callback) callback(response);
        },
        *queryPowerList({payload,callback},{call,put}){
            const response=yield call(queryPowerList,payload);
            yield  put({
                type:'PowerChange',
                payload:response,
            })
            if(callback)callback(response)
        },
        *queryAllSeller({payload,callback},{call,put}){
            const response=yield call(queryAllSeller,payload);
            yield put({
                type:'sellerChange',
                payload:response,
            })
        }
    },
    reducers: {
        changeSubmitting(state, {payload}) {
            return ({
                ...state,
                submitting: payload,
            })
        },
        queryAdminPowerListHandle(state, {payload}) {
            return ({
                ...state,
                data:payload["resultData"]["adminInfo"],
                actionDescs: payload["resultData"]["actionDescs"],
            })
        },
        PowerChange(state,{payload}){
          return({
              ...state,
              powerData:payload.resultData.powerList,
              actionList:payload.resultData.actionList,
              actionList2:payload.resultData.actionList2,
          })
        },
        sellerChange(state,{payload}){
            return({
                ...state,
                sellerData:payload.resultData.AllSeller,
            })
        },
    }
};





